﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATM.DataAccess;
using ATM.Entity;
using ATM.Commons;
using System.Data;

namespace ATM.Bussiness
{
    public class BankMainSystem
    {
        private AccountDAO accDAOObject = null;
        private ATMCardDAO atmCardDAOObject = null;

        public BankMainSystem()
        {
            accDAOObject = new AccountDAO();
            atmCardDAOObject = new ATMCardDAO();
        }

        public int AuthenticateUser(string strCardID, string strPIN)
        {
            try
            {
                int intResult = atmCardDAOObject.Authenticate(strCardID, strPIN);
                return intResult;
            }catch(Exception ex)
            {
                return 0;
            }
        }

        public string AddNewCard(ATMCard atmObject)
        {
            if (atmObject == null)
            {
                return ErrorHandling.NULL_OBJECT;
            }
            if (string.IsNullOrEmpty(atmObject.StrName))
            {
                return ErrorHandling.NULL_PROPERTIES;
            }
            int intResult = accDAOObject.AddNewCard(atmObject);
            if (intResult == 1)
            {
                return "Create Succesfull !!!";
            }
            else
            {
                return "Create Fails !!!! Please try again .";
            }
        }

        public String ModifyValidatyCard(bool blState)
        {
            try
            {
                int intResult = accDAOObject.ModifyCardInfo(blState);
                if (intResult == 1)
                {
                    return "Succesfull !!! ";
                }
                if (intResult == 0)
                {
                    return "Modify Error !!! Please try again .";
                }
            }
            catch (Exception ex)
            {
                return "Modify Error !!! Please try again .";
            }
            return "Succesfull !!! ";
        }

        public int ValidateCard(string strCardId)
        {
            if (string.IsNullOrEmpty(strCardId))
            {
                return 0;
            }
            else
            {
                int intResult = atmCardDAOObject.ValidateCard(strCardId);
                return intResult;
            }
        }
        public  string ValidateAccNumber(string strAccNumber)
        {
              if(!string.IsNullOrEmpty(strAccNumber))
              {
                  return accDAOObject.ValidateAccountNumber(strAccNumber);
              }
              else
              {
                  return string.Empty;
              }
        }
    }
}